package finalfinancialanalyst.business;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;

public class BudgetList implements Serializable{
    
        private static final long serialVersionUID = 1L;
 
	private ArrayList<Budget> budgets;
        private static BudgetList instance;
	 
	private BudgetList() {
                budgets = new ArrayList<Budget>();
	}
        
        public static BudgetList getInstance() {
            if (instance == null) {
                
                //Try to load from file
                instance = (BudgetList)IO.loadFromFile(IO.getBudgetsFile());
                if (instance == null) {
                   instance = new BudgetList(); 
                }
            }
            return instance;
        }

	public ArrayList getList() {
		return budgets;
	}
	 
	public boolean addBuget(Budget bud) {
		return (budgets.add(bud));
	}
	 
	public boolean delBudget(Budget bud) {
		return (budgets.remove(bud));
	}
	
        /*
	public Budget retrieveBudget(String name) {
           for (Budget bud : budget) {
                    if (bud.getName().equalsIgnoreCase(name)) {
                        return bud;
                    }
                }
                return null;    
        } */
	 
	public boolean saveCSV(File file) {
		return false;
	}
	 
	public boolean loadCSV(File file) {
		return false;
	}
	 
	public Map getStats() {
		return null;
	}
         
        public String toCSVString() {
                StringBuilder buff = new StringBuilder();
                Budget [] obj = (Budget[]) budgets.toArray();
                for(int i = 0; i<obj.length-1; i++){
                        buff.append(obj[i].toCSVString());
                        buff.append(",");
                }
                buff.append(obj[obj.length-1].toCSVString());
                return buff.toString();
        }
}
 
